import com.lbi.framework.mvc.io.xml.XMLModel;

import asunit.framework.TestCase;

/**
 * @author michaelforrest
 */
class io.XMLModelTest extends TestCase {

	private var test_obj : XMLModel;
	
	public function XMLModelTest(testMethod : String) {
		super(testMethod);
	}
	private function testSingleItem():Void{
		test_obj = XMLModel.createFromXMLString('<test_obj><item attribute="attribute value">value</item></test_obj>');
		assertEquals(null,"attribute value", test_obj["item"]["attribute"]);
		assertEquals(null,"value", test_obj["item"]);
		//assertEquals("inspection should work this way", "item{\n\tattribute: attribute value\n\tvalue: value\n}",test_obj.inspect());
	}
	private function testMultipleItems():Void{
		test_obj = XMLModel.createFromXMLString('<test_obj><item attribute="attribute">first</item><item>second</item><item>third</item></test_obj>');
		
		assertEquals(3, test_obj.item.length);
		assertEquals("first",	test_obj.item[0]);	
		assertEquals("second",	test_obj.item[1]);	
		assertEquals("third",	test_obj.item[2]);
		assertEquals("if no index is given then resolve to the first item", "attribute",test_obj.item.attribute);
		assertNull("if value is not found, should return null", test_obj.blah);
		assertEquals("if nested value is not found, should still return null", null, test_obj.blah.blah);
	}
/*	private function testImplicitlyConvertsToString() : Void{
		test_obj = XMLModel.createFromXMLString('<test_obj><node>string value</node></test_obj>');
		assertEquals('string value', test_obj.node);
		assertEquals('string',test_obj.node.split()[0]);
	}
	 *
	 */
	private function testNestedMultipleNodesWork() :Void{
		test_obj = XMLModel.createFromXMLString('<profile><reports><report><rating type="integer">7</rating></report><report><rating type="integer">5</rating></report><report><rating type="integer">5</rating></report></profile>');
		assertEquals(3,test_obj.reports.report.length);	
	}
	// TODO: MAKE THIS PARSE
//	private function testCanStillAccessSingleItemArraysAsArray() : Void{
//		test_obj = XMLModel.createFromXMLString('<item id="1">item</item>');
//		assertEquals("1",test_obj.id);
//		assertSame("test_obj=" +test_obj + ", test_obj[0]=" + test_obj[0],test_obj,test_obj[0]);
//	}
}